package com.jiezhuo.controller.jw;

import com.jiezhuo.entity.LoginUser;
import com.jiezhuo.entity.cmeduSchool.JzgNewMenu;
import com.jiezhuo.entity.jw.JwNewAppmenu;
import com.jiezhuo.service.jw.JwUserlistService;
import com.jiezhuo.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@Api(tags = "教务菜单权限管理")
public class JwUserListController {
    @Autowired
    JwUserlistService jwUserlistService;
    @ApiOperation("获取页面菜单")
    @GetMapping("getJzGMenuTree")
    public R getMenuTree(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        String userId=loginUser.getUser().getUserid();

        ArrayList<JzgNewMenu> MenuTree= jwUserlistService.getMenuTree(userId);
        return R.ok().data("menuTree",MenuTree);
    }

    @ApiOperation("获取可用权限")
    @GetMapping("getUserPermissionInfo")
    public R getUserPermissionInfo(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        String userId=loginUser.getUser().getUserid();
        R userPermissionInfo = jwUserlistService.getUserPermissionInfo(userId);
        return userPermissionInfo;
    }


}
